package com.lagou.codec;

import com.lagou.pojo.RpcRequest;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author zhouyp
 * @program code
 * @description
 * @create 2020-06-13
 */
public class RpcEncoder extends MessageToByteEncoder<RpcRequest> {

	private final Serializer serializer;

	public RpcEncoder(Serializer serializer) {
		this.serializer = serializer;
	}

	@Override
	protected void encode(ChannelHandlerContext ctx,
	                      RpcRequest msg, ByteBuf out) throws Exception {
		byte[] bytes = serializer.serialize(msg);
		out.writeBytes(bytes);
	}


}
